import api from "../../../common/api"
// pages/mine//myCompany/myCompany.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // status: true,
    content: undefined,
    company: '',
    inviteCode: undefined,
  },
  inviteCode(e){
    this.setData({
      inviteCode: e.detail.value
    })
  },
  applyFor(){
    api.getCompany({
      inviteCode: this.data.inviteCode
    },res => {
      if(res.data.isSuccess){
        this.setData({
          content: 'yes',
          company: res.data.content.shopAllName
        })
        let company = {
          id:res.data.content.id,
          shopAllName: res.data.content.shopAllName,
          shopShortName: res.data.content.shopShortName,
        }
        wx.setStorageSync('company', company)
      }else {
        this.setData({
          content: 'err'
        })
      }
    })
  },
  close(){
    this.setData({
      content: null
    })
  },
  goChooseStore(){
    wx.navigateTo({
      url: '/pages/mine/chooseStore/chooseStore',
    })
  },
  send(){
    var mobile = app.globalData.sessionUser.mobile;
    let data = {
      mobile,
      activityName: '企业申请',
      activityCode: 'businessApplication',
    }
    wx.showModal({
      title: '您是否申请开通企业服务？',
      success (res) {
        if (res.confirm) {
        api.addPartner(data,res=>{
          if(res.data.isSuccess){
            wx.showToast({
              title: '您已申请开通企业服务，树懒客服将会尽快与您联系',
              duration: 2000,
              icon:'none'
            })
          }else {
            wx.showToast({
              title: '申请失败',
              icon:'none'
            })
          }
        })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
   
},
back(){
  wx.navigateBack({
    delta: 1
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      if(options.status==1){
        this.setData({
          content: 'wait'
        })
      }
      let company = wx.getStorageSync('company').shopAllName;
      this.setData({
        company
      })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})